home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / database / powerbase / docs / Validate < prev   
Encoding:
Text File  |  1997-02-21  |  15.1 KB  |  285 lines

  1.             CH 5 − INPUT VALIDATION AND VALIDATION TABLES
  2.             =============================================
  3. Powerbase can apply two kinds of data input validation:−
  4.  
  5. •       Character validation
  6. •       Table validation
  7.  
  8. 5.1 Character validation
  9. ========================
  10. This means exercising control over what characters a field will accept. RISC
  11. OS provides the means to allow writable icons to accept only certain
  12. characters, or ranges of characters, and reject others. The disallowed
  13. characters are simply ignored so that attempts to type them have no effect.
  14.  
  15. If you open Powerbase’s own application directory (Shift/double-click) you
  16. will find a file called ValStrings. You are recommended not to alter this
  17. file unless you understand exactly what you are doing and, if you do so, to
  18. keep a copy of the original. Examining it, however, can give you an insight
  19. into the validation process. Look, for example, at the entry “03 Number”.
  20. This refers to field type 3 (Numeric). The line below is the validation
  21. string of the writable icon which makes up a numeric field. It looks like
  22. this:−
  23.  
  24.                 Pptr_write,4,4;A0-9.+\-
  25.  
  26. The initial “P” is a command and signifies “pointer”. “ptr_write” is the
  27. name of the sprite used to represent the mouse pointer when it is over this
  28. type (and many other types) of field. You will have noticed that the usual
  29. RISC OS arrow changes to a blue vertical bar, somewhat resembling the caret,
  30. when over a writable field. “4,4” specifies the “active point” of the
  31. pointer. The next character is a semicolon which indicates that a new
  32. command follows.
  33.  
  34. The “A” which comes next is the command “Allow” and is the part of the
  35. validation string which especially concerns us. It determines what
  36. characters the field will allow you to type. In this case they are the
  37. numerals 0-9, the decimal point and the plus and minus signs. Why the
  38. back-slash before the latter? Because “-” is a special character in an icon
  39. validation string (used, as in this case, to specify a range of characters)
  40. and so are the semicolon, tilde (~) and the backslash itself. To include any
  41. of these four characters in the validation string you must precede it with a
  42. backslash.
  43.  
  44. A couple of further examples should be sufficient. “01 Alphanumeric” uses
  45. the same pointer type but the characters accepted are <space> (immediately
  46. after the “A” for “allow”), the upper-case letters A-Z, the lower-case
  47. letters a-z, the numerals 0-9, some common punctuation and the “½”
  48. character. You might want to add to this list. “06 Calculated” uses a
  49. different pointer sprite (ptr_calc, which resembles a pocket calculator) and
  50. has no “Allow” command at all. (You can’t type into this type of field; its
  51. value is calculated from other fields.)
  52.  
  53. 5.2 Validation tables
  54. =====================
  55. Table validation is used where a record field is only allowed to have
  56. certain “values”. A manufacturing company, for instance, will have a product
  57. code for every item it makes and a database of customers which the firm
  58. supplies will make use of such codes to identify the items. It is essential
  59. that whoever enters data is prevented from typing a spurious code. This can
  60. be achieved by linking the appropriate field to a validation table. Fields
  61. linked in this way are recognizable by having their text dark green instead
  62. of black. Powerbase will allow you to type invalid data into the field
  63. initially but, when you click the mouse over a new field or type Return, the
  64. linked validation table is scanned to see whether what you entered in the
  65. field is on the allowed list. If it isn’t Powerbase will restore the
  66. previous contents of the field and print an error message.
  67.  
  68. Validation tables have other uses too. They can have extra columns
  69. containing other data about the products, such as a name and a brief
  70. description, and lists can be printed in which this more understandable data
  71. appears instead of the codes.  You can also have Powerbase replace the
  72. typed-in code with a longer, more readable, form immediately on entry.
  73. Provided the substitute data will fit in the field replacement occurs when
  74. you type Return or click the mouse in another field. If the replacement is
  75. too long then the typed-in data will be unchanged.  This can be a great
  76. timesaver when a lot of data has to be entered.
  77.  
  78. The F.E. college database referred to in 2.2.4 makes extensive use of
  79. validation tables for subjects, courses, tutors and schools of origin. Not
  80. only does this trap typing errors but the data entry is greatly speeded up
  81. when one can type ELL instead of English Language and Literature, yet have
  82. the latter printed out on a list by selecting the Expand switch in the Print
  83. options window.
  84.  
  85. 5.3  Creating a validation table
  86. ================================
  87. Choose Create table from the Validation submenu. Give the table a suitable
  88. name and enter the number of rows required. This will be the maximum number
  89. of items on the allowed list. (It is possible to increase the number later
  90. if necessary.) Next place the caret in the first row (row 0) of the
  91. scrolling list and enter the width (in characters) and the heading
  92. (optional) for the first column of the validation table.
  93.  
  94. If the table is to be used to constrain data entry to a allowed list one
  95. column may be all you need. The most common situation, however, is to have
  96. two columns, the first holding the allowed list and the second being an
  97. expansion or explanation of the former. Use the next row of the scrolling
  98. list to enter the column width and heading for the second table column.  It
  99. is possible to use very large and complex validation tables with all kinds
  100. of data associated with each item on the allowed list.  There is room for
  101. information about 20 columns, but even this can be increased if necessary
  102. (see 14.7).
  103.  
  104. You can, if you wish, choose the foreground and background colours of both
  105. the heading and the body of your table by clicking repeatedly with SELECT or
  106. ADJUST on the Heading and Data icons. Whether this changes the foreground or
  107. background colour depends on which of the two radio buttons is selected.
  108.  
  109. When you are satisfied with the data click Create and the table will be
  110. created in memory. It is not saved on disc at this stage.  You may enter
  111. data into it now or later. Entries may be freely altered and overwritten.
  112. The table will be saved when you close the database or quit Powerbase but,
  113. if you want to play safe, click Force update on the keypad.
  114.  
  115. 5.4  Linking tables to fields
  116. =============================
  117. To link your newly-created validation table to a field click MENU over the
  118. field and choose Link to table from the Field submenu.*  A pair of “bump”
  119. icons, with the usual pop-up menu alternative, lets you cycle through the
  120. tables in memory.  When you have the name of the required table displayed
  121. choose the column of the table to which the field is to be linked. It is
  122. recommended that column 0 normally provide the link (and therefore contain
  123. the data items for the allowed list) and this is set by default. You may,
  124. however, link to any column in the table and another pair of bump icons lets
  125. you cycle through the column numbers.
  126.  
  127. Select Linked to table and click on OK. You will now see that the foreground
  128. colour of the linked field has changed from black to green. Place the caret
  129. in the field and click on List values on the keypad. The validation table
  130. should be displayed.
  131.  
  132. 5.4.1 The Replace on entry feature
  133. ----------------------------------
  134. If you select this switch before linking the table a third pair of bump
  135. icons becomes active, allowing you to choose which column of the table will
  136. replace the data which you type in. In the F.E. college database referred to
  137. in 5.2 the short subject codes (e.g. CHE) would be in the first column and
  138. the longer names (e.g. Chemistry) in the second. On typing CHE <Return>
  139. Powerbase would replace it with Chemistry. In such cases both the entries in
  140. the allowed list proper and those in the replacement list are considered
  141. equally valid and either may be typed. you could actually type Chemistry if
  142. you wished, instead of just CHE, but the former will obviously take longer
  143. to enter and you are far more likely to make a mistake (in which case
  144. Powerbase would object).
  145.  
  146. 5.4.2 When to turn off the Exact match switch
  147. ---------------------------------------------
  148. The Exact match switch is normally selected to indicate that the only user
  149. inputs which will be accepted are those which exactly match an entry on the
  150. allowed list.  Deselecting the switch allows you to type inputs which are
  151. longer (but not shorter) than the entries on the allowed list so long as the
  152. leftmost part of the input matches such an entry. The unmatched “tail” of
  153. your typed entry will be attached to the end of the replacement string. This
  154. feature is intended for use with the Replace on entry facility. Suppose your
  155. database records numbers of items called Widgets, Doodahs and Thingummies.
  156. You decide to identify these names with the codes W, D and T, put the codes
  157. in the first column of the table and the names in the second and select
  158. Replace on entry. You can then type W <Return> and it will be replaced with
  159. Widgets. What you might want, however, is to type W7 and have it replaced
  160. with Widgets, 7.  Deselecting Exact match allows you to do just that since
  161. the W in W7 matches an entry in the validation list. The “expanded” entry in
  162. the second column is made to read “Widgets, ” and Powerbase tacks the
  163. unmatched part of your entry onto the end of this so that W7 is replaced
  164. with Widgets, 7.
  165.  
  166. 5.5  Displaying validation tables
  167. =================================
  168. Placing the mouse pointer over a linked record field and double-clicking
  169. with SELECT makes a small window pop up to the right of the field.  This
  170. shows all the data which is on the same row of the validation table as the
  171. linked item. The item from the allowed list is highlighted in green and the
  172. item (if any) to be substituted on entry is shown in red.  This feature is
  173. very useful if you are examining a database which uses coded data and you
  174. encounter a code which you haven’t seen before.
  175.  
  176. You can also make this window appear automatically whenever the caret enters
  177. a linked field. To turn on this feature choose Preferences from the icon-bar
  178. menu and select the Display linked table data switch.
  179.  
  180. When linked to a field in the database record the complete table may be
  181. displayed by placing the caret in the linked field and clicking on the
  182. keypad button List values (F9). Alternatively, any table present in memory,
  183. whether linked to a data field or not, may be displayed by selecting it from
  184. the Display table submenu (reached from the Validation submenu).
  185.  
  186. 5.6  The validation table menu
  187. ==============================
  188. Clicking MENU over a displayed table offers a menu with entries as follows:−
  189.  
  190. Clear
  191. -----
  192. Removes all data from the table, leaving it blank. Since wiping out a
  193. table in this way is pretty drastic you will be asked to confirm the
  194. operation before it actually takes place. When you close a database all the
  195. validation tables in memory are written to the disc so you will over-write
  196. your disc copy with the blank table.  It is possible to recover the table
  197. using Undo all provided the table has not been closed.
  198.  
  199. Save
  200. ----
  201. Leads to a Save box in which the default pathname points to a directory
  202. called ValTables inside the database application directory. Since that’s
  203. where Powerbase expects to find the tables for a database you should
  204. normally accept this pathname by clicking on Save or typing Return. Only if
  205. you are transferring tables from one database to another should you need to
  206. drag the icon to a filer window. All validation tables in memory are, in any
  207. case, saved to the ValTables directory when you close the database or quit
  208. Powerbase and you can also make this happen at any time by clicking on Force
  209. update on the keypad.
  210.  
  211. Print
  212. -----
  213. Outputs the contents of a validation table in the same format as a
  214. report. The output appears in a window from which it may be saved as a text
  215. file (see 3.1.1).
  216.  
  217. Sort column <n>
  218. ---------------
  219. Will sort the table on the nth column, that being the one
  220. the mouse pointer was over when you clicked MENU on the table.
  221.  
  222. Undo change
  223. -----------
  224. Will restore the specific item which you were pointing at when
  225. you clicked MENU to the state it was in when the table was displayed.
  226.  
  227. Undo all
  228. --------
  229. Restores the entire table to the state it was in when first
  230. displayed, even if Clear has been used. You cannot undo changes if you have
  231. closed the table then re-displayed it.
  232.  
  233. Save as CSV
  234. -----------
  235. Leads to a Save box from which the table contents can be saved
  236. as a CSV file. The default pathname points to the database’s PrintJobs
  237. directory.
  238.  
  239. Modify
  240. ------
  241. Brings up the same window as you used to create the table. You may
  242. then increase the number of rows, add extra columns, alter the order of
  243. existing columns or, indeed, do anything sensible. Be careful about renaming
  244. columns; combining this with shuffling the columns about is apt to cause
  245. confusion − Powerbase isn’t a mind-reader! When you have made the required
  246. changes click on  Modify.
  247.  
  248. 5.7  Loading validation tables
  249. ==============================
  250. A table linked to a field is automatically loaded when the database is
  251. opened. If not yet linked, however, the table won’t be in memory unless you
  252. have just created it. To load the table choose Show table files from the
  253. Validation submenu (Ctrl Q). The contents of the ValTables directory will be
  254. displayed and the required tables can dragged onto the record window (or
  255. simply double-clicked). As each table is dropped it will be displayed.
  256.  
  257. There may be times when the user wishes to use a validation table to hold
  258. some data, but doesn’t want to use it to validate input into a field or to
  259. link it to a field at all. It is possible to load a validation table once
  260. the database is open by using the procedure described in the previous
  261. paragraph, but a more convenient solution is to add a “!” character to the
  262. end of the table’s name. Powerbase will then load it whether any field is
  263. linked to it or not.
  264.  
  265. 5.8  Including validation table data in printouts
  266. =================================================
  267. Validation tables are often used to allow short codes to be entered in
  268. records but with a link to a more descriptive entry in another column of the
  269. table.  If this is all that is required then always put the data which makes
  270. up the actual allowed list, i.e. the items which are allowed in the fields
  271. of the main record, into the first column of the table and set the link from
  272. the record field to this column (column 0). The more detailed “expanded”
  273. entry should go in column 1. Printing with the Expand switch in the Print
  274. options window selected  will then print the column 1 instead of the column
  275. 0 entry.
  276.  
  277. You can, however, include data from other columns of a table by displaying
  278. the table  and clicking in the required columns with ADJUST, exactly like
  279. selecting main record fields for printing (see 3.3.1). It is immaterial
  280. which row you click on; only the column matters and the highlighting to show
  281. which columns are selected always appears in the first row. The columns
  282. selected in all tables are saved as part of a print selection and may
  283. therefore be retrieved for future use. As well as highlighting the required
  284. columns you will also need to select the Expand switch as described above.
  285. Printed reports will then include all the data from the highlighted columns.